// pages/volunteer/activity/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active:0,
    img:"https://img.yzcdn.cn/vant/cat.jpeg",
    list:[
      {
        'title':'红色教育进校园活动',
        'thumb':'https://img.yzcdn.cn/vant/cat.jpeg',
      },
      {
        'title':'红色教育进校园活动',
        'thumb':'https://img.yzcdn.cn/vant/cat.jpeg',
      },
      {
        'title':'红色教育进校园活动',
        'thumb':'https://img.yzcdn.cn/vant/cat.jpeg',
      },
    ],
    list0:[],
    list1:[],
    list2:[],
    currentpage0:0,
    currentpage1:0,
    currentpage2:0,
    query:{
      page:0,
      status:0
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const that = this
    that.api_activity0();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const that = this
    that.api_activity(that.data.active)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onShareTimeline(){

  },
  onChangeTab(e) {
    console.log(e)
    const that = this
    that.setData({
      active:e.detail.name
    })
    const data = {
      status:e.detail.name
    }
    that.api_activity(e.detail.name)
  },
  api_activity(status) {
    const that = this
    if(status == 0) {
      that.api_activity0();
    }
    if(status == 1) {
      that.api_activity1();
    }
    if(status == 2) {
      that.api_activity2();
    }
    
  },
  api_activity0() {
    const that = this
    that.data.query.status = 0;
    that.data.query.page = that.data.currentpage0 + 1;
    app.api.get(app.getUrl('volunteer.activity'),that.data.query).then((res)=>{
      if(res.data.length>0) {
        that.data.list0 = that.data.list0.concat(res.data);
        that.setData({
          list0:that.data.list0,
          currentpage0: res.pagination.current
        })
      }
      
    })
  },
  api_activity1() {
    const that = this
    that.data.query.status = 1;
    that.data.query.page = that.data.currentpage1 + 1;
    app.api.get(app.getUrl('volunteer.activity'),that.data.query).then((res)=>{
      if(res.data.length>0) {
        that.data.list1 = that.data.list0.concat(res.data);
        that.setData({
          list1:that.data.list1,
          currentpage1:res.pagination.current
        })
      }
    })
  },
  api_activity2() {
    const that = this
    that.data.query.status = 2;
    that.data.query.page = that.data.currentpage2 + 1;
    app.api.get(app.getUrl('volunteer.activity'),that.data.query).then((res)=>{
      if(res.data.length>0) {
        that.data.list2 = that.data.list0.concat(res.data);
        that.setData({
          list2:that.data.list2,
          currentpage2:res.pagination.current
        })
      }
    })
  }

})